<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="小区名称" prop="premiseName">
        <el-input
          v-model="queryParams.premiseName"
          placeholder="请输入小区名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="租客姓名" prop="tenantName">
        <el-input
          v-model="queryParams.tenantName"
          placeholder="请输入租客姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <template>
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="房租收款计划" name="first">
          <el-row :gutter="10" class="mb8">
            <left-toolbar :showSearch.sync="showSearch" @queryTable="findList"></left-toolbar>
          </el-row>

          <el-table v-loading="loading" :data="planList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="租房合同号" align="center" prop="contractNo" />
            <el-table-column label="收款单号" align="center" prop="receiptOrderNo" />
            <el-table-column label="承租房间" align="center" prop="roomName" />
            <el-table-column label="租客姓名" align="center" prop="tenantName" />
            <el-table-column label="小区名称" align="center" prop="premiseName" />
            <el-table-column label="支付金额" align="center" prop="paymentAmount" />
            <el-table-column label="账单" align="center" prop="receiptNumber">
              <template slot-scope="scope">
                {{reces(scope.row.receiptNumber)}}
              </template>
            </el-table-column>
            <el-table-column label="收款状态" align="center" prop="skStatus'">
              <template slot-scope="scope">
                {{skStatausa(scope.row.skStatus)}}
              </template>
            </el-table-column>
            <el-table-column label="账单类型" align="center" prop="billType" >
              <template slot-scope="scope">
                {{billTypes(scope.row.billType)}}
              </template>
            </el-table-column>
            <el-table-column label="应收日期" align="center" prop="collectionDate" />
            <el-table-column label="实收日期" align="center" prop="realCollectionDate" />
            <el-table-column label="支付方式" align="center" prop="payMethod" >
              <template slot-scope="scope">
                {{payMethods(scope.row.payMethod)}}
              </template>
            </el-table-column>
            <el-table-column label="操作人" align="center" prop="operationUser" />
          </el-table>

          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="findList"
          />

        </el-tab-pane>

        <el-tab-pane label="租务收款计划" name="second">
          <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="findListaaa"></right-toolbar>
          </el-row>

          <el-table v-loading="loading" :data="hzhList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="租房合同号" align="center" prop="contractNo" />
            <el-table-column label="收款单号" align="center" prop="receiptOrderNo" />
            <el-table-column label="承租房间" align="center" prop="roomName" />
            <el-table-column label="租客姓名" align="center" prop="tenantName" />
            <el-table-column label="小区名称" align="center" prop="premiseName" />
            <el-table-column label="支付金额" align="center" prop="paymentAmount" />
            <el-table-column label="账单" align="center" prop="receiptNumber">
              <template slot-scope="scope">
                {{reces(scope.row.receiptNumber)}}
              </template>
            </el-table-column>
            <el-table-column label="收款状态" align="center" prop="skStatus'">
              <template slot-scope="scope">
                {{skStatausa(scope.row.skStatus)}}
              </template>
            </el-table-column>
            <el-table-column label="账单类型" align="center" prop="billType" >
              <template slot-scope="scope">
                {{billTypes(scope.row.billType)}}
              </template>
            </el-table-column>
            <el-table-column label="应收日期" align="center" prop="collectionDate" />
            <el-table-column label="实收日期" align="center" prop="realCollectionDate" />
            <el-table-column label="支付方式" align="center" prop="payMethod" >
              <template slot-scope="scope">
                {{payMethods(scope.row.payMethod)}}
              </template>
            </el-table-column>
            <el-table-column label="操作人" align="center" prop="operationUser" />
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParamss.pageNum"
            :limit.sync="queryParamss.pageSize"
            @pagination="findListaaa"
          />


        </el-tab-pane>
      </el-tabs>
    </template>
  </div>
</template>

<script>
import { findList,listPlan, getPlan, delPlan, addPlan, updatePlan } from "@/api/finance/plan";

export default {
  name: "Plan",
  components: {
  },
  data() {
    return {
      activeName: 'first',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收款计划表格数据
      planList: [],

      hzhList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      queryParamss:{
        pageNum: 1,
        pageSize: 10,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        receiptOrderNo: null,
        businessId: null,
        contractId: null,
        contractNo: null,
        contractType: null,
        tTerminationId: null,
        premiseId: null,
        premiseName: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        ownerId: null,
        ownerName: null,
        tenantId: null,
        tenantName: null,
        receiptType: null,
        skStatus: null,
        billType: null,
        itemType: null,
        otherItemName: null,
        paymentAmount: null,
        realPaymentAmount: null,
        withReceiptPlanId: null,
        paymentDaysBegin: null,
        paymentDaysEnd: null,
        collectionDate: null,
        realCollectionDate: null,
        receiptNumber: null,
        payMethod: null,
        otherPayMethod: null,
        payFlowNo: null,
        rentalPrice: null,
        tax: null,
        operationUser: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        receiptOrderNo: [
          { required: true, message: "收款单号不能为空", trigger: "blur" }
        ],
        businessId: [
          { required: true, message: "商户ID不能为空", trigger: "blur" }
        ],
        contractId: [
          { required: true, message: "合同ID不能为空", trigger: "blur" }
        ],
        contractNo: [
          { required: true, message: "合同编号不能为空", trigger: "blur" }
        ],
        contractType: [
          { required: true, message: "合同类型,'1：收房合同，2：出房合同'不能为空", trigger: "change" }
        ],
        premiseId: [
          { required: true, message: "楼盘ID不能为空", trigger: "blur" }
        ],
        premiseName: [
          { required: true, message: "小区(使用楼盘名)不能为空", trigger: "blur" }
        ],
        delFlg: [
          { required: true, message: "删除标识,0:未删除，1：删除不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.findList();
  },
  methods: {
    reces(val){
      return "第"+val+"期";
    },
    payMethods(val){
      return val==1 ? '快捷同' : val == 2 ? '支付宝' : val==3 ? '微信' : val==4 ? '现金' : val==5 ? '银行卡转账': val==6? 'POS机刷卡':''
    },
    billTypes(val){
      return val==1 ? '分期变更' : val == 2 ? '租约保理变更' : val==3 ? '退租变更' : val==4 ? '普通账单' : ''
    },
    skStatausa(val){
      return val==1 ? '未收款' : val == 2 ? '已收款' : val==3 ? '已终止' : val==4 ? '已冻结' : ''
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    /** 查询收款计划列表 */
    findList() {
      this.loading = true;
      listPlan(this.queryParams).then(response => {
        this.planList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    findListaaa(){
      this.loading = true;
      findList(this.queryParamss).then(response => {
        console.log(response.rows);
        this.hzhList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        receiptOrderNo: null,
        businessId: null,
        contractId: null,
        contractNo: null,
        contractType: null,
        tTerminationId: null,
        premiseId: null,
        premiseName: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        ownerId: null,
        ownerName: null,
        tenantId: null,
        tenantName: null,
        receiptType: null,
        skStatus: 0,
        billType: null,
        itemType: null,
        otherItemName: null,
        paymentAmount: null,
        realPaymentAmount: null,
        withReceiptPlanId: null,
        paymentDaysBegin: null,
        paymentDaysEnd: null,
        collectionDate: null,
        realCollectionDate: null,
        receiptNumber: null,
        payMethod: null,
        otherPayMethod: null,
        payFlowNo: null,
        rentalPrice: null,
        tax: null,
        operationUser: null,
        remark: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.findList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收款计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPlan(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收款计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePlan(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlan(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除收款计划编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPlan(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('finance/plan/export', {
        ...this.queryParams
      }, `finance_plan.xlsx`)
    }
  }
};
</script>
